<?php

class RespondentList {

  private $list = array();
  private $db;

  public function __construct($loadData = true) {
    $this->db = Db::getConnection();
    if ($loadData) {
      $this->loadAll();
    }
  }

  public function getData($table, $field) {
  	$resultArray = array();
  	foreach ($this->list as $respondent) {
  		$resultArray[$respondent->getValue($table, $field)]++;
  	}
		return $resultArray;
  }
  
  private function loadAll() {
    $ids = $this->db->select("SELECT id FROM respondent");
    foreach ($ids as $id) {
      $this->list[] = new Respondent($id['id']);
    }
  }

  public function createRespondent($data) {
    $respondent = new Respondent();
    $respondent->addNew($data);
    $this->list[] = $respondent;
  }

}